<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin extends CI_Controller {

	public function index()
	{
		$this->load->view('adminLogin');
	}

	public function login()
	{
		$username = $this->input->post('username');
		$password = $this->input->post('password');

		$this->load->model('User_model');
		
		$this->load->helper('email');
		
		$isemail = valid_email($username);
 
        $userinfo = $this->User_model->login($username,$password,$isemail);
		
		if($userinfo)	
		{
			//设置session变量
			$this->session->set_userdata(array('uid'=>$userinfo['uid'],'username'=>$userinfo['username'],'roleid'=>$userinfo['roleid']));
			//跳转到控制台
			redirect('c=console&m=index', 'refresh');
		}
		$userinfo['message']="登录失败，用户名或密码错误！";
		$this->load->view('adminLogin',$userinfo);
	}
}